/**
 * Leetcode 804. Unique Morse Code Words
 * https://leetcode.com/problems/unique-morse-code-words/description/
 *
 * @author Kevin
 * @date 2018-11-26
 */
public class Solution {

    public static void main(String[] args) {
        String[] words = {"hi", "hello"};
        int res = new Solution().uniqueMorseRepresentations(words);
        System.out.println(res);
    }


    public int uniqueMorseRepresentations(String[] words) {

        String[] codes = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
        BST<String> bst = new BST<>();
        for (String word : words) {
            StringBuilder res = new StringBuilder();
            for (int i = 0; i < word.length(); i++) {
                res.append(codes[word.charAt(i) - 'a']);
            }

            if (!bst.contains(res.toString())) {
                bst.add(res.toString());
            }
        }

        return bst.getSize();
    }
    
}
